package io;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
/**
 * 对象流作用:进行对象的序列化和反序列化
 * 本例演示序列化
 */
public class OosDemo {
    public static void main(String[] args) throws IOException {
        String name = "范传奇";
        int age = 25;
        String gender = "男";
        String[] otherInfo = {"帅","技术好","玩游戏好","有钱","你们二阶段的老师"};
        Person person = new Person(name,age,gender,otherInfo);

        FileOutputStream fos = new FileOutputStream("person.obj"); //低级流(文件流)
        ObjectOutputStream oos = new ObjectOutputStream(fos); //高级流(对象流)
        /*
          对象输出流在进行序列化时，要求该对象必须实现可序列化接口Serializable
          否则调用writeObject()时会发生NotSerializableException异常
         */
        oos.writeObject(person); //写出对象(序列化)
        System.out.println("写出完毕");
        oos.close();
    }
}












